Lambda 可以使用现成已经实现的方法。
要求被调用的方法的参数类型和返回值和 Lambda 表达式中函数接口中抽象方法的参数类型和返回值一致
对象::实例方法名
1 | Consumer<String> consumer = x -> System.out.println(x); |
1 | Consumer<String> consumer = x -> System.out.println(x); |
类::静态方法名
1 | Comparator<Integer> comparator = (x, y) -> Integer.compare(x, y); |
类::实例方法名
要求 第一个参数是实例方法的调用者,第二个参数是实例方法的参数
1 | BiPredicate<String, String> biPredicate = (x, y) -> x.equals(y); |
构造函数引用
可以自动匹配对应的构造函数
1 | Supplier<String> supplier = () -> new String(); |
1 | Function<String, String> function = (x) -> new String(x); |
数组引用
1 | Function<Integer, String[]> function = (x) -> new String[x]; |